unit UAMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls,
  UPRealLayers, StdCtrls, IdBaseComponent, IdComponent, IdRawBase,
  IdRawClient, IdIcmpClient;

type
  TForm1 = class(TForm)
    Im: TImage;
    IdIcmpClient1: TIdIcmpClient;
    procedure IdIcmpClient1Reply(ASender: TComponent;
      const AReplyStatus: TReplyStatus);
    procedure FormDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ImMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure ImMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    AniList:TBMLList;
  end;


TMyThread = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;

var
  Form1: TForm1;
  Host:string;
  MyMove:boolean=false;
  MyThread:TMyThread;
procedure startAni;

implementation

uses UP_XML,UPUtil;

{$R *.dfm}


procedure ping;
begin  with form1 do begin
IdIcmpClient1.Host := Host;
IdIcmpClient1.ReceiveTimeout := 300; //0.5 seconds timeout
  try
  IdIcmpClient1.Ping;
  except
  ShowMessage('Error when pinging');
  end;
end; end;

procedure TMyThread.Execute;
begin
  while not Terminated do Ping;
end;

procedure TForm1.IdIcmpClient1Reply(ASender: TComponent;
  const AReplyStatus: TReplyStatus);
begin
  if (AReplyStatus.ReplyStatusType = rsTimeOut) or (AReplyStatus.ReplyStatusType = rsErrorUnreachable)
  then begin
    MyMove:=false;//Label1.Caption :='Where are you?';
  end else begin 
   // Label1.Caption :='Here Is the iPhone';
    MyMove:=True;//'Packet round trip time: ' + IntToStr(AReplyStatus.MsRoundTripTime) + ' ms.';
  end;
end;


Var Up,Le:boolean;
procedure AniShowBMP(BMP:TBitmap);
begin
with Form1 do with Im.Picture.Bitmap do
  begin
  Assign(BMP);
  Canvas.Pixels[0,0]:=Canvas.Pixels[0,0]; //bug in assign
            //needs this pix write to recover the when transparent=true;
  if MyMove Then
    begin
    if up then top :=top-2 else top:=top+2;
    if Le then Left :=Left+2 else Left:=Left-2;
    if left<0 then le:=true else
      if left>screen.Width-width then le:=false;
    if top<0 then up:=false else
      if top>screen.Height-height then up:=true;
    end;
  end;
end;

procedure TForm1.FormDblClick(Sender: TObject);
begin
form1.Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Doublebuffered:=true;
UPUtil.ShowBMP:= AniShowBMP;
AniList:=TBMLList.create;
If ParamCount=3 then
  begin
  width:=strtoint(paramstr(2));
  height:=strtoint(paramstr(3));
  end;
host:=PingTrigRead;
//MyThread:=TMyThread.Create(false);
end;


procedure startAni;
begin
Fxml.OpenDialog1.FileName:=paramstr(1);
Fxml.OpenXMLfile;
Form1.AniList.getlistfromXML(extractfilepath(paramstr(1)));
Form1.AniList.Timer.Enabled:=true;
end;

var
sx,sy:integer;
procedure TForm1.ImMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if ssLeft in shift then
  begin
  left:=left-sx+x;
  top:=top-sy+y;
  end;
end;

procedure TForm1.ImMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 sx:=x;
 sy:=y;
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin  {
MyThread.Terminate;
MyThread.WaitFor;
MyThread.Free; }
end;

end.
